package models;

import fleporcq.simpleReflect.ClassDescriptor;
import utils.MetaModel;

import java.util.ArrayList;
import java.util.List;


public class EntityDescriptor extends ClassDescriptor {

    private static final String JPA_PACKAGE = "play.db.jpa";

    public EntityDescriptor(Class clazz) {
        super(clazz);
    }

    @Override
    public boolean hasSuperClass() {
        if(super.hasSuperClass()){
            Package pack = this.clazz.getSuperclass().getPackage();
            if(pack!=null){
                return pack != Package.getPackage(JPA_PACKAGE);
            }
            return true;
        }
        return false;
    }

    @Override
    public ClassDescriptor getSuperDescriptor() {
        return new EntityDescriptor(this.clazz.getSuperclass());
    }

    public static List<EntityDescriptor> all() {
        List<EntityDescriptor> entityDescriptors = new ArrayList<EntityDescriptor>();
        List<Class> entities = MetaModel.getEntities();
        for (Class entity : entities) {
            entityDescriptors.add(new EntityDescriptor(entity));
        }
        return entityDescriptors;
    }

}
